package phase1_testCase;
import phase1.Block;
import junit.framework.TestCase;
import java.util.Vector;
public class Block_testCase extends TestCase{
	private Block block;


	public void setUp() { block = new Block(); }

	public void tearDown() {}
	

	//(A)Test the method getNumOfChar():
	//Test1: Block(' ',' ',' ')
	public void test1GetNumOfChar() {
		int result;
		block =new Block(' ',' ',' ');
		result = block.getNumOfChar();
		assertEquals(result, 0);
	}
	//Test2: Block('A',' ',' ')
	public void test2GetNumOfChar() {
		int result;
		block =new Block('A',' ',' ');
		result = block.getNumOfChar();
		assertEquals(result, 1);
	}
	//Test3: Block('A','B',' ')
	public void test3GetNumOfChar() {
		int result;
		block =new Block('A','B',' ');
		result = block.getNumOfChar();
		assertEquals(result, 2);
	}
	//Test4: Block('A','B','C')
	public void test4GetNumOfChar() {
		int result;
		block =new Block('A','B','C');
		result = block.getNumOfChar();
		assertEquals(result, 3);
	}
	//(B)Test the method addChar()
	//Test 1 :Block(' ',' ',' ')  inputChar ='Z'
	public void test1AddChar() {
		boolean result;
		block =new Block(' ',' ',' ');
		char inputChar='Z';
		result = block.addChar(inputChar);
		assertEquals(result, true);
	}
	//Test 2 :Block('A',' ',' ') inputChar ='Y'
	public void test2AddChar() {
		boolean result;
		block =new Block('A',' ',' ');
		char inputChar='Y';
		result = block.addChar(inputChar);
		assertEquals(result, true);
	}
	//Test 3 :Block('A','B',' ') inputChar ='X'
	public void test3AddChar() {
		boolean result;
		block =new Block('A','B',' ');
		char inputChar='X';
		result = block.addChar(inputChar);
		assertEquals(result, true);
	}
	//Test 4 :Block('A','B','C') inputChar ='W'
	public void test4AddChar() {
		boolean result;
		block =new Block('A','B','C');
		char inputChar='W';
		result = block.addChar(inputChar);
		assertEquals(result, false);
	}
	//(C)Test the method chChar()
	//Test 1 :Block('X','Y','Z') inputChar ='A' inputInt=0
	public void test1ChChar() {
		boolean result;
		block =new Block('X','Y','Z');
		int inputInt=0;
		char inputChar='A';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, true);
	}
	//Test 2 :Block('X','Y','Z') inputChar ='B' inputInt=1
	public void test2ChChar() {
		boolean result;
		block =new Block('X','Y','Z');
		int inputInt=1;
		char inputChar='B';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, true);
	}
	//Test 3 :Block('X','Y','Z') inputChar ='C' inputInt=2
	public void test3ChChar() {
		boolean result;
		block =new Block('X','Y','Z');
		int inputInt=2;
		char inputChar='C';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, true);
	}
	//Test 4 :Block('A','B','C') inputChar ='D' inputInt=3
	public void test4ChChar() {
		boolean result;
		block =new Block('A','B','C');
		int inputInt=3;
		char inputChar='D';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, false);
	}
	//Test 5 :Block(' ',' ',' ') inputChar ='D' inputInt = 0
	public void test5ChChar() {
		boolean result;
		block =new Block(' ',' ',' ');
		int inputInt=0;
		char inputChar='D';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, false);
	}
	//Test 6 :Block(' ',' ',' ') inputChar ='D' inputInt = 1
	public void test6ChChar() {
		boolean result;
		block =new Block(' ',' ',' ');
		int inputInt=1;
		char inputChar='D';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, false);
	}
	//Test 7 :Block(' ',' ',' ') inputChar ='D' inputInt = 2
	public void test7ChChar() {
		boolean result;
		block =new Block(' ',' ',' ');
		int inputInt=2;
		char inputChar='D';
		result = block.chChar(inputInt,inputChar);
		assertEquals(result, false);
	}
	//(C)Test the method getChar()
	//Test 1 :Block('A','B','C') inputInt ='0'
	public void test1GetChar() {
		char result;
		block =new Block('A','B','C');
		int inputInt=0;		
		result = block.getChar(inputInt);
		assertEquals(result, 'A');
	}
	//Test 2 :Block('A','B','C') inputInt ='1'
	public void test2GetChar() {
		char result;
		block =new Block('A','B','C');
		int inputInt=1;		
		result = block.getChar(inputInt);
		assertEquals(result, 'B');
	}
	//Test 3 :Block('A','B','C') inputInt ='2'
	public void test3GetChar() {
		char result;
		block =new Block('A','B','C');
		int inputInt=2;		
		result = block.getChar(inputInt);
		assertEquals(result, 'C');
	}
	//Test 4 :Block('A','B','C') inputInt ='3'
	public void test4GetChar() {
		char result;
		block =new Block('A','B','C');
		int inputInt=3;		
		result = block.getChar(inputInt);
		assertEquals(result, '?');
	}
	//(D)Test the method getPreviousBlock()
	//Test 1: Set Block('A','B','C') Block('D','E','F') Block('G','H','I') as previous block .
	public void test1GetPreviousBlock() {
		boolean result=true;
		block =new Block();
		Block P1 =new Block('A','B','C');
		Block P2 =new Block('D','E','F');
		Block P3 =new Block('G','H','I');
		block.setPreviousBlock(P1);
		block.setPreviousBlock(P2);
		block.setPreviousBlock(P3);
		char dummyChar='A';					
		for(int i=0;i<block.getPreviousBlock().size();i++)
		{	
			for(int j=0;j<block.getPreviousBlock().get(i).getNumOfChar();j++)
			{	
				if(dummyChar != block.getPreviousBlock().get(i).getChar(j))		
				{
					result=false;
				}
				dummyChar++;
			}
		}
		assertEquals(result, true);
	}
	//Test 2: Set Block('A','A','A') Block('A','B','A') Block('A','A','A') as previous block .
	public void test2GetPreviousBlock() {
		boolean result=true;
		block =new Block();
		Block P1 =new Block('A','A','A');
		Block P2 =new Block('A','B','A');
		Block P3 =new Block('A','A','A');
		block.setPreviousBlock(P1);
		block.setPreviousBlock(P2);
		block.setPreviousBlock(P3);
		char dummyChar='A';					
		for(int i=0;i<block.getPreviousBlock().size();i++)
		{	
			for(int j=0;j<block.getPreviousBlock().get(i).getNumOfChar();j++)
			{	
				if(dummyChar != 'A')		
				{
					result=false;
				}
				dummyChar++;
			}
		}
		assertEquals(result, false);
	}
	//(E)Test the method getNextBlock()
	//Test 1:Set Block('A','B','C') Block('D','E','F') Block('G','H','I') as Next block .
	public void test1GetNextBlock() {
		boolean result=true;
		block =new Block();
		Block P1 =new Block('A','B','C');
		Block P2 =new Block('D','E','F');
		Block P3 =new Block('G','H','I');
		block.setNextBlock(P1);
		block.setNextBlock(P2);
		block.setNextBlock(P3);
		char dummyChar='A';					
		for(int i=0;i<block.getNextBlock().size();i++)
		{	
			for(int j=0;j<block.getNextBlock().get(i).getNumOfChar();j++)
			{	
				if(dummyChar != block.getNextBlock().get(i).getChar(j))		
				{
					result=false;
				}
				dummyChar++;
			}
		}
		assertEquals(result, true);
	}
	//Test 2:Set Block('A','A','A') Block('A','B','A') Block('A','A','A') as Next block .
	public void test2GetNextBlock() {
		boolean result=true;
		block =new Block();
		Block P1 =new Block('A','A','A');
		Block P2 =new Block('A','B','A');
		Block P3 =new Block('A','A','A');
		block.setNextBlock(P1);
		block.setNextBlock(P2);
		block.setNextBlock(P3);
		char dummyChar='A';					
		for(int i=0;i<block.getNextBlock().size();i++)
		{	
			for(int j=0;j<block.getNextBlock().get(i).getNumOfChar();j++)
			{	
				if(dummyChar != 'A')		
				{
					result=false;
				}
				dummyChar++;
			}
		}
		assertEquals(result, false);
	}
	//(F)Test the method setNextBlock()
	//Block('A','B','C');
	public void testSetNextBlock() {
		int result;
		block =new Block();
		Block P1 =new Block('A','B','C');
		block.setNextBlock(P1);
		result=block.getNextBlock().size();

		assertEquals(result, 1);
	}
	//(G)Test the method setPreviousBlock()
	//Block('A','B','C');
	public void testSetPreviousBlock() {
		int result;
		block =new Block();
		Block P1 =new Block('A','B','C');
		block.setNextBlock(P1);
		result=block.getNextBlock().size();

		assertEquals(result, 1);
	}
	
	//test toString method
	public void testToString(){
		String result;
		block =new Block('A','B','C');
		result = block.toString();
		assertEquals(result, "A B C");
	}
	
	//test toString method if there is space
	public void testToString2(){
		String result;
		block =new Block('A','B',' ');
		result = block.toString();
		assertEquals(result, "A B");
	}
}